package com.aidex.quartz.task;

import com.aidex.common.utils.JsonHelper;
import com.aidex.common.utils.http.HttpUtils;
import com.aidex.risk.domain.*;
import com.aidex.system.domain.Waybill;
import com.aidex.system.domain.WaybillDetail;
import com.aidex.system.service.WaybillDetailService;
import com.aidex.system.service.WaybillService;
import com.aidex.system.service.impl.GoodsRiskInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author JMY
 */
@Component("sendTask")
public class SendTask
{
    @Autowired
    private WaybillService waybillService;
    @Autowired
    private WaybillDetailService detailService;

    public tradeGoodsRiskApi sendTradeGoodsRiskApi() throws UnsupportedEncodingException {
        tradeGoodsRiskApi tradeGoodsRiskApi = new tradeGoodsRiskApi();
        trade_goods_risk_api trade_goods_risk_api = new trade_goods_risk_api();
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        trade_goods_risk_api.setSend_time(sdf.format(d));
        trade_goods_risk_api.setSender("航空货运安检模型");
        String str = UUID.randomUUID().toString();
        String temp = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + str.substring(24);
        trade_goods_risk_api.setBusiness_no(temp);
        trade_goods_risk_api.setApi_desc("6.4综合风险等级、疑似风险标注");
        trade_goods_risk_api.setApi_type("");
        List<tradeGoodsRiskApiContent> contentList = new ArrayList<>();
        tradeGoodsRiskApiContent content = new tradeGoodsRiskApiContent();
        String json =JsonHelper.getInstance().writeValueAsString(createDemoTrade());
        Base64.Decoder decoder = Base64.getDecoder();
        Base64.Encoder encoder = Base64.getEncoder();
        byte[] textByte = json.getBytes("UTF-8");
        final String encodedText = encoder.encodeToString(textByte);
        content.setContent(encodedText);
        contentList.add(content);
        trade_goods_risk_api.setRequest_list(contentList);

        tradeGoodsRiskApi.setTrade_goods_risk_api(trade_goods_risk_api);

        return tradeGoodsRiskApi;
    }
    static tradeGoodsRiskHead createDemoTrade()
    {
        tradeGoodsRiskHead head = new tradeGoodsRiskHead();
        head.setWayBillID("2021092712300005"); //运单ID
        head.setWayBillNo("123456"); //运单号
        head.setDataSource("ALMS"); //运单来源
        head.setRiskRating("高风险"); //综合风险等级（低风险\优先\普通\高风险\严控）
        head.setRiskClassification("高风险"); //货物风险等级（普通\低风险\高风险）
        head.setAgentLevel("D"); //代理人等级
        head.setIsImportantFlights("Y"); //重点航班标识

        List<tradeGoodsRiskDetial> detials = new ArrayList<>();
        tradeGoodsRiskDetial detial = new tradeGoodsRiskDetial();
        detials.add(detial);
        detial.setTradeName( "华为手机MATE10"); //货品名
        detial.setTradeNameKey( "华为手机"); //货品名关键词
        detial.setTradeType( "1"); //货品名所属清单（0-无；1-X光机难辨识清单；2-疑似风险货物清单；3-隐含性危险品清单）
        detial.setTradeRiskClassification( "高风险"); //货物风险等级（普通\低风险\高风险）
        detial.setTradeRiskRating( "高风险" );//综合风险等级（低风险\优先\普通\高风险\严控）

        detial = new tradeGoodsRiskDetial();
        detials.add(detial);
        detial.setTradeName( "华为手机MATE8"); //货品名
        detial.setTradeNameKey( "华为手机"); //货品名关键词
        detial.setTradeType( "1"); //货品名所属清单（0-无；1-X光机难辨识清单；2-疑似风险货物清单；3-隐含性危险品清单）
        detial.setTradeRiskClassification( "高风险"); //货物风险等级（普通\低风险\高风险）
        detial.setTradeRiskRating( "高风险" );//综合风险等级（低风险\优先\普通\高风险\严控）
        head.setTradeGoodsRiskDetials(detials);
        return head;
    }
}

